package com.mrd.serverconnect.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mrd.serverconnect.R;

import java.util.List;

/**
 * Created by cww on 2020/9/17.
 */

public class ChooseDataAdapter extends BaseAdapter{
    private final Context context;
    private final List<String> list;
    private int showPosition;

    public ChooseDataAdapter(Context context, List<String> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder holder;
        if (convertView==null){
            holder=new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_chosee,parent,false);
            holder.tvChoose = convertView.findViewById(R.id.tv_choose);
            convertView.setTag(holder);
        }else {
            holder = (MyHolder) convertView.getTag();
        }

        holder.tvChoose.setText(list.get(position));
        if (showPosition==position){
            holder.tvChoose.setTextColor(context.getResources().getColor(R.color.color_blue));
        }else {
            holder.tvChoose.setTextColor(context.getResources().getColor(R.color.color_white));
        }
        return convertView;
    }

    public void changeSeleted(int integer) {
        this.showPosition = integer;
        notifyDataSetChanged();
    }

    class MyHolder{
        TextView tvChoose;
    }
}
